package com.example.admin.yuejian21.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.admin.yuejian21.Adapter.TrainlistAdapter;
import com.example.admin.yuejian21.Bean.train;
import com.example.admin.yuejian21.Bean.traindetail;
import com.example.admin.yuejian21.Model.TrainModel;
import com.example.admin.yuejian21.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * A simple {@link Fragment} subclass.
 */
public class TrainAllFragment extends Fragment {

    private RecyclerView recyclerView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.fragment_train_all,container,false);
        recyclerView = (RecyclerView) view.findViewById(R.id.trainall_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        showData();
        return view;
    }
    private void showData(){
        TrainModel trainModel = new TrainModel();
        Call<List<traindetail>> call = trainModel.gettrainlists();
        call.enqueue(new Callback<List<traindetail>>() {
            @Override
            public void onResponse(Call<List<traindetail>> call, Response<List<traindetail>> response) {
                List<traindetail> mDataList = response.body();
                recyclerView.setAdapter(new TrainlistAdapter(TrainAllFragment.this.getContext(),mDataList));//设置适配器，绑定Adapter.
            }

            @Override
            public void onFailure(Call<List<traindetail>> call, Throwable t) {

            }
        });
    }

}

